package org.wyl.xiachufang.spider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Spider;

import java.util.ArrayList;
import java.util.List;

@Component
public class FoodSpiderRunner {

    @Autowired
    private FoodSpider foodSpider;
    @Autowired
    private FoodPipeline foodPipeline;

    public void start() {
        // 40081
        List<String> urls = new ArrayList<>();
        for (int i = 57; i <= 81; i++) {
            urls.add("https://hanwuji.xiachufang.com/category/400" + i + "/");
        }
//        urls.add("https://hanwuji.xiachufang.com/category/40057/");
        String[] urlArr = urls.toArray(new String[]{});

        Spider.create(foodSpider)
                .addUrl(urlArr)
                .addPipeline(foodPipeline)
                .thread(5)
                .run();
    }
}
